# coding=utf-8
"""
@Time ： 2022/7/28 13:55
@Auth ： Mr. hzs
@Function ：请输入模块功能描述
"""
class SortAlgorithm:
    def __init__(self,params):
        self.params = params

    def choose(self):
        for j in range(len(self.params) - 1):
            maxindex = 0
            for i in range(1, len(self.params) - j):
                if self.params[i] > self.params[maxindex]:
                    maxindex = i
            self.params[maxindex], self.params[len(self.params) - 1 - j] = self.params[len(self.params) - 1 - j], self.params[maxindex]

    def bubbling(self):
        for j in range(len(self.params) - 1):
            for i in range(0, len(self.params) - 1 - j):
                if self.params[i] > self.params[i + 1]:
                    self.params[i], self.params[i + 1] = self.params[i + 1], self.params[i]

    def speediness(self, weight, left, right):
        base = weight[right]
        l = left
        h = right
        while l < h:
            while l < h:
                if weight[l] > base:
                    weight[l], weight[h] = weight[h], weight[l]
                    h -= 1
                    break
                else:
                    l += 1

            while l < h:
                if weight[h] < base:
                    weight[l], weight[h] = weight[h], weight[l]
                    l += 1
                    break
                else:
                    h -= 1
        if l - 1 - left > 0:
            self.speediness(weight, left, l - 1)

        if right - h - 1 > 0:
            self.speediness(weight, h + 1, right)

if __name__ == '__main__':
    params1 = [155, 165, 160, 175, 170, 185, 180, 190, 165, 175, 185]
    SSS = SortAlgorithm(params1)
    SSS.choose()
    print(params1)

    params2 = [185, 175, 165, 190, 180, 185, 170, 175, 160, 165, 155]
    SSS = SortAlgorithm(params2)
    SSS.bubbling()
    print(params2)

    weight = [185, 175, 165, 190, 180, 185, 170, 175, 160, 165, 155, 150, 145, 140, 135, 130, 200, 120, 195, 165, 100, 185]
    SSS = SortAlgorithm(weight)
    SSS.speediness(weight,0,len(weight) - 1)
    print(weight)
